package com.iseastar.guojiang.newcabinet;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.iseastar.BaseActivity2;
import com.iseastar.guojiang.model.ServiceTaskBean;
import com.shouhuobao.station.R;

import droid.frame.app.Callback;
import droid.frame.ui.utils.Utils;
import droid.frame.utils.Android;
import droid.frame.view.CodeLinearLayout;

/**
 * Created by joker on 2017/12/23.
 * 验证寄件码弹出框
 */
@Deprecated
public class ConfirmSendCodeDialogActivity extends BaseActivity2 {

    private ServiceTaskBean serviceTaskBean = null;
    private int type;//0 寄件码  1 收件码

    @SuppressLint("MissingSuperCall")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // 第二个方法在此参数无效
        overridePendingTransition(R.anim.in_bottom2top, 0);
        serviceTaskBean = (ServiceTaskBean) getIntent().getSerializableExtra("item");
        type = getIntent().getIntExtra("type", 0);
        Window win = getWindow();
        win.getDecorView().setPadding(0, 0, 0, 0);
        //         win.getDecorView().setMinimumWidth((int) (win.getWindowManager().getDefaultDisplay().getWidth() * 0.6));// 设置dialog的宽度
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
        // lp.horizontalMargin = 300;
        lp.gravity = Gravity.CENTER;
        win.setAttributes(lp);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.activity_task_send_code);
        super.findViewById();
        if (type == 1) {
            ((TextView) findViewById(R.id.title_tv)).setText("请输入收件码");
        } else {
            ((TextView) findViewById(R.id.title_tv)).setText("请输入寄件码");
        }
        final CodeLinearLayout codeLinearLayout = (CodeLinearLayout) findViewById(R.id.task_sendcode_input_layout);
        ImageView cancelIV = (ImageView) findViewById(R.id.close_iv);
        TextView messageTipsTV = (TextView) findViewById(R.id.send_message_tip_tv);
        if (serviceTaskBean != null) {
            if (type == 1) {
                messageTipsTV.setText("收件码已发送到" + serviceTaskBean.getGivePhone() + "手机上\n也可在火箭令牌中获取");
            } else {
                messageTipsTV.setText("寄件码已发送到" + serviceTaskBean.getPhone() + "手机上\n也可在火箭令牌中获取");
            }
            codeLinearLayout.setCallback(new Callback() {
                @Override
                public void execute(Object... result) {
                    String code = codeLinearLayout.getText();
                    if (code.length() == 6) {
                        Intent intent = new Intent();
                        intent.putExtra("code", code);
                        setResult(Activity.RESULT_OK, intent);
                        finish();
                    }
                }
            });
        }
        cancelIV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(0, R.anim.out_top2bottom);
        Android.hideSoftInput(getContext());
    }
}
